import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BookingResourceRequirementApi } from '#/api/spa/booking/resourcerequirement';

import { getDictOptions, getRangePickerDefaultProps } from '#/utils';
import { DICT_SPA_TYPE } from '#/utils/dictSpa';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'bookingOrderId',
      label: '预约订单ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入预约订单ID',
      },
    },
    {
      fieldName: 'orderDetailId',
      label: '订单明细ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入订单明细ID',
      },
    },
    {
      fieldName: 'requirementCode',
      label: '需求编码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入需求编码',
      },
    },
    {
      fieldName: 'resourceType',
      label: '资源类型',
      rules: 'required',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择资源类型',
      },
    },
    {
      fieldName: 'resourceCategory',
      label: '资源分类',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入资源分类',
      },
    },
    {
      fieldName: 'resourceId',
      label: '资源',
      component: 'Input',
      componentProps: {
        placeholder: '请输入资源ID（可为空，表示任意资源）',
      },
    },
    {
      fieldName: 'resourceName',
      label: '资源名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入资源名称',
      },
    },
    {
      fieldName: 'resourceCode',
      label: '资源编码',
      component: 'Input',
      componentProps: {
        placeholder: '请输入资源编码',
      },
    },
    {
      fieldName: 'requiredQuantity',
      label: '需求数量',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入需求数量',
      },
    },
    {
      fieldName: 'requiredDuration',
      label: '需求时长(分钟)',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入需求时长(分钟)',
      },
    },
    {
      fieldName: 'requiredStartTime',
      label: '需求开始时间',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'requiredEndTime',
      label: '需求结束时间',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'constraintRules',
      label: '约束规则',
      component: 'Input',
      componentProps: {
        placeholder: '请输入约束规则',
      },
    },
    {
      fieldName: 'preferenceRules',
      label: '偏好规则',
      component: 'Input',
      componentProps: {
        placeholder: '请输入偏好规则',
      },
    },
    {
      fieldName: 'exclusionRules',
      label: '排除规则',
      component: 'Input',
      componentProps: {
        placeholder: '请输入排除规则',
      },
    },
    {
      fieldName: 'lockStatus',
      label: '锁定状态',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'lockTime',
      label: '锁定时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'lockUserId',
      label: '锁定操作人ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入锁定操作人ID',
      },
    },
    {
      fieldName: 'lockNotes',
      label: '锁定备注',
      component: 'Input',
      componentProps: {
        placeholder: '请输入锁定备注',
      },
    },
    {
      fieldName: 'allocationStatus',
      label: '分配状态',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'allocationTime',
      label: '分配时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'allocationUserId',
      label: '分配操作人ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入分配操作人ID',
      },
    },
    {
      fieldName: 'allocatedResourceId',
      label: '分配的资源ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入分配的资源ID',
      },
    },
    {
      fieldName: 'allocatedResourceName',
      label: '分配的资源名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入分配的资源名称',
      },
    },
    {
      fieldName: 'allocationNotes',
      label: '分配备注',
      component: 'Input',
      componentProps: {
        placeholder: '请输入分配备注',
      },
    },
    {
      fieldName: 'deliveryStatus',
      label: '交付状态',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'deliveryTime',
      label: '交付时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'deliveryUserId',
      label: '交付操作人ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入交付操作人ID',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'bookingOrderId',
      label: '预约订单ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入预约订单ID',
      },
    },
    {
      fieldName: 'orderDetailId',
      label: '订单明细ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入订单明细ID',
      },
    },
    {
      fieldName: 'requirementCode',
      label: '需求编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入需求编码',
      },
    },
    {
      fieldName: 'resourceType',
      label: '资源类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择资源类型',
      },
    },
    {
      fieldName: 'resourceCategory',
      label: '资源分类',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入资源分类',
      },
    },
    {
      fieldName: 'resourceId',
      label: '资源',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入资源ID（可为空，表示任意资源）',
      },
    },
    {
      fieldName: 'resourceName',
      label: '资源名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入资源名称',
      },
    },
    {
      fieldName: 'resourceCode',
      label: '资源编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入资源编码',
      },
    },
    {
      fieldName: 'requiredQuantity',
      label: '需求数量',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入需求数量',
      },
    },
    {
      fieldName: 'requiredDuration',
      label: '需求时长(分钟)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入需求时长(分钟)',
      },
    },
    {
      fieldName: 'requiredStartTime',
      label: '需求开始时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'requiredEndTime',
      label: '需求结束时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'constraintRules',
      label: '约束规则',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入约束规则',
      },
    },
    {
      fieldName: 'preferenceRules',
      label: '偏好规则',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入偏好规则',
      },
    },
    {
      fieldName: 'exclusionRules',
      label: '排除规则',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入排除规则',
      },
    },
    {
      fieldName: 'lockStatus',
      label: '锁定状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择锁定状态',
      },
    },
    {
      fieldName: 'lockTime',
      label: '锁定时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'lockUserId',
      label: '锁定操作人ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入锁定操作人ID',
      },
    },
    {
      fieldName: 'lockNotes',
      label: '锁定备注',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入锁定备注',
      },
    },
    {
      fieldName: 'allocationStatus',
      label: '分配状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择分配状态',
      },
    },
    {
      fieldName: 'allocationTime',
      label: '分配时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'allocationUserId',
      label: '分配操作人ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入分配操作人ID',
      },
    },
    {
      fieldName: 'allocatedResourceId',
      label: '分配的资源ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入分配的资源ID',
      },
    },
    {
      fieldName: 'allocatedResourceName',
      label: '分配的资源名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入分配的资源名称',
      },
    },
    {
      fieldName: 'allocationNotes',
      label: '分配备注',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入分配备注',
      },
    },
    {
      fieldName: 'deliveryStatus',
      label: '交付状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择交付状态',
      },
    },
    {
      fieldName: 'deliveryTime',
      label: '交付时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'deliveryUserId',
      label: '交付操作人ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入交付操作人ID',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<BookingResourceRequirementApi.BookingResourceRequirement>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
    },
    {
      field: 'bookingOrderId',
      title: '预约订单ID',
      minWidth: 120,
    },
    {
      field: 'orderDetailId',
      title: '订单明细ID',
      minWidth: 120,
    },
    {
      field: 'requirementCode',
      title: '需求编码',
      minWidth: 120,
    },
    {
      field: 'resourceType',
      title: '资源类型',
      minWidth: 120,
    },
    {
      field: 'resourceCategory',
      title: '资源分类',
      minWidth: 120,
    },
    {
      field: 'resourceId',
      title: '资源',
      minWidth: 120,
    },
    {
      field: 'resourceName',
      title: '资源名称',
      minWidth: 120,
    },
    {
      field: 'resourceCode',
      title: '资源编码',
      minWidth: 120,
    },
    {
      field: 'requiredQuantity',
      title: '需求数量',
      minWidth: 120,
    },
    {
      field: 'requiredDuration',
      title: '需求时长(分钟)',
      minWidth: 120,
    },
    {
      field: 'requiredStartTime',
      title: '需求开始时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'requiredEndTime',
      title: '需求结束时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'constraintRules',
      title: '约束规则',
      minWidth: 120,
    },
    {
      field: 'preferenceRules',
      title: '偏好规则',
      minWidth: 120,
    },
    {
      field: 'exclusionRules',
      title: '排除规则',
      minWidth: 120,
    },
    {
      field: 'lockStatus',
      title: '锁定状态',
      minWidth: 120,
    },
    {
      field: 'lockTime',
      title: '锁定时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'lockUserId',
      title: '锁定操作人ID',
      minWidth: 120,
    },
    {
      field: 'lockNotes',
      title: '锁定备注',
      minWidth: 120,
    },
    {
      field: 'allocationStatus',
      title: '分配状态',
      minWidth: 120,
    },
    {
      field: 'allocationTime',
      title: '分配时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'allocationUserId',
      title: '分配操作人ID',
      minWidth: 120,
    },
    {
      field: 'allocatedResourceId',
      title: '分配的资源ID',
      minWidth: 120,
    },
    {
      field: 'allocatedResourceName',
      title: '分配的资源名称',
      minWidth: 120,
    },
    {
      field: 'allocationNotes',
      title: '分配备注',
      minWidth: 120,
    },
    {
      field: 'deliveryStatus',
      title: '交付状态',
      minWidth: 120,
    },
    {
      field: 'deliveryTime',
      title: '交付时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'deliveryUserId',
      title: '交付操作人ID',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
